package register

import (
	"fmt"
	goredislib "github.com/go-redis/redis/v8"
	"github.com/go-redsync/redsync/v4"
	"github.com/go-redsync/redsync/v4/redis/goredis/v8"
)

type ResSyncs interface {
	Lock() error
	UnLock() error
}

type RedSync struct {
	Host    string `json:"host"`
	Port    int    `json:"port"`
	Redsync *redsync.Redsync
}

// redis 分布式锁
func New(host string, port int) *RedSync {

	client := goredislib.NewClient(&goredislib.Options{
		Addr: fmt.Sprintf("%s:%d", host, port),
	})
	pool := goredis.NewPool(client)
	redsync := redsync.New(pool)

	return &RedSync{
		Host:    host,
		Port:    port,
		Redsync: redsync,
	}
}

func (r *RedSync) Lock() error {

	return nil
}

func (r *RedSync) UnLock() error {

	return nil
}
